
export const USER_SIGNIN = 'USER_SIGNIN' //登录成功
export const USER_ASSIGN = 'USER_ASSIGN' // 同步信息
export const USER_SIGNOUT = 'USER_SIGNOUT' //退出登录
export const ISVERIFIED = 'ISVERIFIED' //认证状态


export default {
    state: JSON.parse(window.localStorage.getItem('user'))||{},
    mutations: {

        [USER_SIGNIN](state, user) {
            Object.assign(state, user);
            window.localStorage.setItem('user',JSON.stringify(state))
        },
        [USER_ASSIGN](state, user) {
            Object.assign(state, user);
            window.localStorage.setItem('user',JSON.stringify(state))
        },
        [USER_SIGNOUT](state) {
            for(var key in state){
                delete state[key];
            }
            window.localStorage.removeItem('user')
        },
        [ISVERIFIED](state,obj) {
             state[obj.type] = obj.str;
            window.localStorage.setItem('user',JSON.stringify(state))
        }
    },
    actions: {
        [USER_SIGNIN]({commit}, user) {

            commit(USER_SIGNIN, user)
        },
        [USER_ASSIGN]({commit}, user) {

            commit(USER_ASSIGN, user)
        },
        [USER_SIGNOUT]({commit}) {
            commit(USER_SIGNOUT)
        },
        [ISVERIFIED]({commit},obj) {
            commit(ISVERIFIED,obj)
        }
    }
}